<template>
  <div>
    <h1>图书订单库</h1>
    <el-table :data="tableData" style="width: 100%">
      <el-table-column label="id" width="400" height="200">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.id }}</span>
        </template>
      </el-table-column>
      <el-table-column label="用户名" width="400" height="200">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.username }}</span>
        </template>
      </el-table-column>
      <el-table-column label="订单书" width="400" height="200">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.books }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button size="mini" @click="handleEdit(scope.$index, scope.row)"
            >发货</el-button
          >
          <el-button
            size="mini"
            type="danger"
            @click="handleDelete(scope.$index, scope.row)"
            >取消订单</el-button
          >
        </template>
      </el-table-column>
      <!-- <el-table-column label="角色" width="350" height="100">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.name }}</span>
        </template>
      </el-table-column> -->

      <!-- <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button size="mini" @click="handleEdit(scope.$index, scope.row)"
            >编辑</el-button
          >
          <el-button
            size="mini"
            type="danger"
            @click="handleDelete(scope.$index, scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column> -->
    </el-table>
  </div>
</template>
<script>
export default {
  name: "orderpage",
  data() {
    return {
      tableData: [
        {
          id: "",
          username: "",
          books: "",
          // name: "",
            },
           
      ],
    };
  },
    methods: {
        loadOrder() {
        this.$axios.get("/order").then((resp) => {
            console.log(resp.data);
        //   this.tableData.length=resp.data.length
            // for (var i = 0; i < resp.data.length; i++){
          this.tableData = resp.data
          console.log(resp.data[0].username);
          
                // this.tableData[i].username = resp.data[i].username;
                // this.tableData[i].orderbooks = resp.data[i].title
                // this.tableData[i].role = resp.data[i].name
            // }
      });
    },
      handleDelete(index, row) {
        console.log(row.books);
        var data = new FormData()
        // data.append('orderbook', row.books)
        data.append('id', row.id)
        this.$confirm("是否确定取消订单", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        }).then(() => {
        this.$axios.post("/order/delete", data).then({
          
        }).then((resp) => { 
          if (resp.data.code) {
              this.loadOrder()
          }
             

        })
      })
        
    },
    getOrder() {
     
    },
  },
    mounted: function () {
    this.loadOrder()
  }
};
</script>